package org.springsource.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springsource.dao.AccountDao;
import org.springsource.domain.Account;
import org.springsource.domain.AccountNotFoundException;

@Repository
public class AccountDaoImpl implements AccountDao {

	private static final Logger logger = LoggerFactory.getLogger(AccountDaoImpl.class);
	
	@PersistenceContext
	private EntityManager entityManager;


	@Override
	public Account getAccount(Long number) throws AccountNotFoundException {
		// TODO promeni go
		return entityManager.find(Account.class, number);
	}


	@Override
	public List<Account> getAccounts() {
		return entityManager.createQuery("select a from Account a",Account.class).getResultList();
		
	}


	@Override
	public void saveOrUpdate(Account account) {
		// TODO Auto-generated method stub
		entityManager.persist(account);
		
	}


	@Override
	public void delete(Account account) {
		entityManager.remove(entityManager.merge(account));
		
	}

}
